home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / clib / sys / h / time < prev    next >
Text File  |  1996-11-09  |  5KB  |  138 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/clib/sys/h/RCS/time,v $
  4.  * $Date: 1996/10/30 21:58:59 $
  5.  * $Revision: 1.3 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: time,v $
  10.  * Revision 1.3  1996/10/30 21:58:59  unixlib
  11.  * Massive changes made by Nick Burret and Peter Burwood.
  12.  *
  13.  * Revision 1.2  1996/05/06 09:03:13  unixlib
  14.  * Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
  15.  * Saved for 3.7a release.
  16.  *
  17.  * Revision 1.1  1996/04/19 21:23:56  simon
  18.  * Initial revision
  19.  *
  20.  ***************************************************************************/
  21.  
  22. #ifndef __SYS_TIME_H
  23. #define __SYS_TIME_H 1
  24.  
  25. #ifndef __TIME_H
  26. #include <time.h>
  27. #endif
  28.  
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32.  
  33. /* A time value that is accurate to the nearest
  34.    microsecond but also has a range of years.  */
  35. struct timeval
  36.   {
  37.     int tv_sec;            /* Seconds.  */
  38.     int tv_usec;        /* Microseconds.  */
  39.   };
  40.  
  41. /* POSIX.4 structure for a time value.  This is like a `struct timeval' but
  42.    has nanoseconds instead of microseconds.  */
  43. struct timespec
  44.   {
  45.     long int ts_sec;        /* Seconds.  */
  46.     long int ts_nsec;        /* Nanoseconds.  */
  47.   };
  48.  
  49. /* Macros for converting between `struct timeval' and `struct timespec'.  */
  50. #define TIMEVAL_TO_TIMESPEC(tv, ts) {                                   \
  51.         (ts)->ts_sec = (tv)->tv_sec;                                    \
  52.         (ts)->ts_nsec = (tv)->tv_usec * 1000;                           \
  53. }
  54. #define TIMESPEC_TO_TIMEVAL(tv, ts) {                                   \
  55.         (tv)->tv_sec = (ts)->ts_sec;                                    \
  56.         (tv)->tv_usec = (ts)->ts_nsec / 1000;                           \
  57. }
  58.  
  59.  
  60. /* Structure crudely representing a timezone.
  61.    This is obsolete and should never be used.  */
  62. struct timezone
  63.   {
  64.     int tz_minuteswest;        /* Minutes west of GMT.  */
  65.     int tz_dsttime;        /* Nonzero if DST is ever in effect.  */
  66.   };
  67.  
  68. /* Get the current time of day and timezone information,
  69.    putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
  70.    Returns 0 on success, -1 on errors.
  71.    NOTE: This form of timezone information is obsolete.
  72.    Use the functions and variables declared in <time.h> instead.  */
  73. extern int gettimeofday (struct timeval *, struct timezone *);
  74.  
  75. /* Set the current time of day and timezone information.
  76.    This call is restricted to the super-user.  */
  77. extern int settimeofday (const struct timeval *, const struct timezone *);
  78.  
  79. /* Adjust the current time of day by the amount in DELTA.
  80.    If OLDDELTA is not NULL, it is filled in with the amount
  81.    of time adjustment remaining to be done from the last `adjtime' call.
  82.    This call is restricted to the super-user.  */
  83. extern int adjtime (const struct timeval *, struct timeval *);
  84.  
  85.  
  86. /* Values for the first argument to `getitimer' and `setitimer'.  */
  87. enum __itimer_which
  88.   {
  89.     /* Timers run in real time.  */
  90.     ITIMER_REAL = 0,
  91.     /* Timers run only when the process is executing.  */
  92.     ITIMER_VIRTUAL = 1,
  93.     /* Timers run when the process is executing and when
  94.        the system is executing on behalf of the process.  */
  95.     ITIMER_PROF = 2,
  96.     /* Used in <sys/unix.h>.  */
  97.     __MAX_ITIMERS = 3
  98.   };
  99.  
  100. /* Type of the second argument to `getitimer' and
  101.    the second and third arguments `setitimer'.  */
  102. struct itimerval
  103.   {
  104.     /* Value to put into `it_value' when the timer expires.  */
  105.     struct timeval it_interval;
  106.     /* Time to the next timer expiration.  */
  107.     struct timeval it_value;
  108.   };
  109.  
  110. /* Set *VALUE to the current setting of timer WHICH.
  111.    Return 0 on success, -1 on errors.  */
  112. extern int getitimer (enum __itimer_which, struct itimerval *);
  113.  
  114. /* Set the timer WHICH to *NEW.  If OLD is not NULL,
  115.    set *OLD to the old value of timer WHICH.
  116.    Returns 0 on success, -1 on errors.  */
  117. extern int setitimer (enum __itimer_which, struct itimerval *, struct itimerval *);
  118.  
  119. /* Change the access time of FILE to TVP[0] and
  120.    the modification time of FILE to TVP[1].  */
  121. extern int utimes (char *, struct timeval __tvp[2]);
  122.  
  123.  
  124. /* Convenience macros for operations on timevals.
  125.    NOTE: `timercmp' does not work for >= or <=.  */
  126. #define    timerisset(tvp)        ((tvp)->tv_sec || (tvp)->tv_usec)
  127. #define    timercmp(tvp, uvp, CMP)    \
  128.   ((tvp)->tv_sec CMP (uvp)->tv_sec || \
  129.    (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec CMP (uvp)->tv_usec)
  130. #define    timerclear(tvp)        ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  131.  
  132. #ifdef __cplusplus
  133.     }
  134. #endif
  135.  
  136.  
  137. #endif /* sys/time.h */
  138.